<?
  //Classi di gestione News
  Class News   {

      var $allnews;
      var $evento;
      var $class;
      var $lang;

      function News($evento,$lang,$class)  {
          global $conn;
          if($evento!="")
            $qry_evento = "AND evento='$evento'";
          else
            $qry_evento = "";
		  $qry = "SELECT idnews FROM news WHERE lang='$lang' $qry_evento ORDER BY data DESC;";
		  $rs = $conn->Execute($qry);
		  if($rs)  {
		    $i = 0;
		    $this->allnews = array();
		    while(!$rs->EOF)  {
			  $this->allnews[$i] = new articolo($rs->Fields("idnews"),'','','','','','');
			  $this->allnews[$i]->oneArticolo();
			  $i++;
			  $rs->MoveNext();
			}  
		    $rs->Close();
		  }          
          $this->class = $class;
          $this->evento = $evento;
      }
      
      function list_news()  {
	    global $conn;
		$content = '<table width="100%" border="0" cellspacing="0" cellpadding="0">							<tr>
	<td width=100% class=navbar>
	 '.makeNavbar("NEWS").'
	</td>	
		</tr>';
		$i = 1;
	   if(is_array($this->allnews))  {
		foreach($this->allnews as $i=>$news) {
		  if($i > 1)
		    $bgcolor = " bgcolor=#F6F7F4";
		  else
		    $bgcolor = "";  
		  $content .= '<tr>
                            <td width=100%>
							 <table width="100%" border="0" cellpadding="3" cellspacing="0">
                              <tr>
                                <td'.$bgcolor.'><a class='.$this->class.' href="http://www.bsvillage.com/'.FOLDERNEW.'/allnews.php?idnews='.$news->idnews.'&tipo='.$this->evento.'">'.$news->data.'  '.$news->titolo.'</a></td>
                              </tr>
                            </table></td>
                            </tr>';
         if($i > 1)
		   $i = 1;
		 else
		   $i++;         
		}
	   } else {
	      $content = "<tr>
	       				<td class=$this->class>Nessuna news trovata.</td>
		  			  </tr>";
		}	
		$content .= "</table>";
		return $content;  
	  }
	  
	  function getNewsHome()  {
	    global $conn;
		$news = array();
		for($i=0;$i<4;$i++)  {
			$news[$i] = '<a class='.$this->class.' href="javascript:;" onclick="javascript:window.open(\'dettaglio_news.php?idnews='.$this->allnews[$i]->idnews.'\',\'\',\'width=500,height=400,scrollbars=yes\');">'.$this->allnews[$i]->data.'  '.$this->allnews[$i]->titolo.'</a>';
		}
		 $tmpl_file = "../gestione/templatesphp/news.html";
         $thefile = implode("", file($tmpl_file));
         $thefile = addslashes($thefile);
         $thefile = "\$r_file=\"".$thefile."\";";
         eval($thefile);
		$content = $r_file;		  
	return $content;		  
	  }
	  
      function scroll()  {
      	global $lang;
      	switch($lang)  {
		  case "ita":
		    $all = "Tutte le news";
		  break;
		  
		  case "eng":
		    $all = "All news";
		  break;
		}
        $content = "<MARQUEE behavior= \"scroll\" align= \"center\" direction= \"up\" height=\"130\" scrollamount= \"2\" scrolldelay= \"20\" onmouseover='this.stop()' onmouseout='this.start()'>\n";
        foreach($this->allnews as $i=>$news)  {
         $content .= "<a class=plain href=\"http://www.bsvillage.com/".FOLDERNEW."/allnews.php?idnews=$news->idnews&tipo=$this->evento\">$news->data<br>$news->titolo</a><br><br>\n";
       }
        $content .= "<div align=center><a class=plain href=\"http://www.bsvillage.com/".FOLDERNEW."/allnews.php?tipo=$this->evento\">$all</a></div>
		</MARQUEE>\n";
       return $content;
	  }
	  
	  function doSpotNew($tipo)  {
	  	global $lang;
	    $spot = '<div style="height:20px;vertical-align:middle"><marquee direction="left" width="400" height="20" scrolldelay="20" scrollamount="2">';
		$listSpot = new News($tipo."spot",$lang,"plain");
		   if(is_array($listSpot->allnews))  {
			foreach($listSpot->allnews as $i=>$news) {
			  if($news->testo !="") {
			    $testo = eregi_replace("<p>","",$news->testo);
			    $testo = eregi_replace("</p>","",$testo);
			  }
		       $spot .= "<span style=\"height:20px;vertical-align:middle\">".$testo."</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			}
		   }
		   $spot .= "</marquee></div>";
		return $spot;   	      
	  }
	  
	  function doSpot()  {
	  	global $lang;
	    $spot = '<div style="height:20px;vertical-align:middle"><marquee direction="left" width="400" height="20" scrolldelay="20" scrollamount="2">';
		$listSpot = new News("y",$lang,"plain");
		   if(is_array($listSpot->allnews))  {
			foreach($listSpot->allnews as $i=>$news) {
			  if($news->testo !="") {
			    $testo = eregi_replace("<p>","",$news->testo);
			    $testo = eregi_replace("</p>","",$testo);
			  }
		       $spot .= "<span style=\"height:20px;vertical-align:middle\">".$testo."</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			}
		   }
		   $spot .= "</marquee></div>";
		return $spot;   	      
	  }
	  
	  function doSpotCross()  {
	  	global $lang;
	    $spot = '';
		$listSpot = new News("y",$lang,"plain");
		   if(is_array($listSpot->allnews))  {
			foreach($listSpot->allnews as $i=>$news) {
			  if($news->testo !="")
		       $spot .= "<span style=\"height:20px;vertical-align:middle\" nowrap>".$news->testo."</span>&nbsp;&nbsp;&nbsp;";
			}
		   }
		return $spot;   	      
	  }
	  
	  function getRss() {
		/*$xml = new XMLFile();
		$fh = fopen('http://www.blogpiscine.com/feed', 'r');
		$xml->read_file_handle( $fh );
		fclose( $fh );
		$root = &$xml->roottag;
		$tagname = $root->name;
		$tagdata = $root->cdata;
		$channel = $root->tags[0];*/
		$listnews = '<MARQUEE style="margin-left:10px;" behavior= "scroll" align= "center" direction= "up" width="200" height="300" scrollamount= "2" scrolldelay= "20" onmouseover="this.stop()" onmouseout="this.start()">';
		/*foreach($channel->tags as $i=>$newtag)  {
		  if($i > 8)  {
		    $tagtitle = $newtag->tags[0];
		    $taghref = $newtag->tags[1];
			$tagcat = $newtag->tags[5];
			$listnews .= '<a class="plain" href="'.$taghref->cdata.'" target="_BLANK">'.utf8_decode($tagtitle->cdata)."</a><br><br>\n";
		  }
		}*/
		$listnews .= '<script type="text/javascript">newsblogpiscine();</script>';
		
		$listnews .= '</marquee>';
		return $listnews;
	  }
	  
  function list_newsRSS()  {
	    global $conn;
  		$xml = new XMLFile();
		$fh = fopen('http://www.blogpiscine.com/feed', 'r');
		$xml->read_file_handle( $fh );
		fclose( $fh );
		$root = &$xml->roottag;
		$tagname = $root->name;
		$tagdata = $root->cdata;
		$channel = $root->tags[0];
		$content = '<table width="100%" border="0" cellspacing="0" cellpadding="0">	
		<tr>
	<td width=100% class=navbar>
	 '.makeNavbar("NEWS").'
	</td>	
		</tr>';
		$i = 1;
		foreach($channel->tags as $n=>$newtag)  {
		  if($n > 8)  {
		    $tagtitle = $newtag->tags[0];
		    $taghref = $newtag->tags[1];
			$tagcat = $newtag->tags[5];
			if($i > 1)
		      $bgcolor = " bgcolor=#F6F7F4";
		  	else
		      $bgcolor = "";  
		    $content .= '<tr>
                            <td width=100%>
							 <table width="100%" border="0" cellpadding="3" cellspacing="0" class="plain">
                              <tr>
                                <td'.$bgcolor.'><a class="plain" href="'.$taghref->cdata.'" target="_BLANK">'.utf8_decode($tagtitle->cdata).'</a><br></td>
                              </tr>
                            </table></td>
	                            </tr>';
	         if($i > 1)
			   $i = 1;
			 else
			   $i++; 
		  }
		}	
		$content .= "</table>";
		return $content;  
	  }
}

  Class articolo   {
        
        var $idnews;
        var $data;
        var $titolo;
        var $testo;
        var $lang;
        var $mail_autore;
        var $evento;

        function articolo($idnews, $data, $titolo, $testo, $lang, $mail_autore, $evento)   {
                 $this->idnews = $idnews;
                 $this->data = $data;
                 $this->titolo = $titolo;
                 $this->testo = $testo;
                 $this->lang = $lang;
                 $this->mail_autore = $mail_autore;
                 $this->evento = $evento;

        }

        function oneArticolo()   {
          		global $conn;
                 $idnews = $this->idnews;
                 $qry = "SELECT data,titolo,testo,lang,mail_autore,evento FROM news WHERE idnews='$idnews';";
                 $res1 = $conn->Execute($qry);
                 list($data, $titolo, $testo, $lang, $mail_autore, $evento) = @array_values($res1->FetchRow());
                 $res1->Close();
                 list($a, $m, $g) = explode("-",$data);
                 $data = "$g-$m-$a";
                 $this->data = $data;
                 $this->titolo = $titolo;
                 $this->testo = $testo;
                 $this->lang = $lang;
                 $this->mail_autore = $mail_autore;
                 $this->evento = $evento;
        }


        function save()   {
                 global $conn;
                 $qry = "INSERT INTO news VALUES (NULL, '$this->data', '$this->titolo', '$this->testo', '$this->lang', '$this->mail_autore', '$this->evento')";
                 $rs = $conn->Execute($qry);
                if ($rs)  {
                 $this->idnews = $conn->Insert_ID();
                 header("Location:news.php");
				 $error = 0;
				 $rs->Close();
				 return $error;
                }  else  {
                 $error = "<table width=100%>";
                 $error .= "<tr><td class=error align=\"center\"><b>Errore nell'inserimento!</b><br><a href=\"javascript:history.go(-1);\"><img src=\"imgs/indietro.gif\" alt=\"Indietro\" border=\"0\"></a></td></tr></table>";
				 return $error;
               }

        }

        function update()  {
                 global $conn,$lang;
                 $qry = "UPDATE news SET data='$this->data', titolo='$this->titolo', testo='$this->testo', mail_autore='$this->mail_autore',evento='$this->evento' WHERE idnews='$this->idnews' AND lang='$lang';";
                $rs = $conn->Execute($qry);
                if ($rs)  {
                 $error =  "<table width=100%><tr><td align=\"center\" class=error><b>News aggiornata con successo!</b></td></tr></table>";
                $rs->Close(); 
                }  else  {
                 $error =  "<table width=100%><tr><td class=error align=center><b>Errore nell'aggiornamento!</b><br><a href=\"javascript:history.go(-1);\"><img src=\"imgs/indietro.gif\" alt=\"indietro\" border=0></a></td></tr></table>";
               }
			   return $error;
        }

        function delete()  {
                 global $conn,$lang;
                 $qry = "DELETE FROM news WHERE idnews='$this->idnews' AND lang='$lang';";
                 $rs = $conn->Execute($qry);
                if ($rs)  {
                 $error = 0;
                 $rs->Close();
                }  else  {
                 echo "<table width=100%><tr><td class=error align=center><b>Errore nell'operazione!</b><br><a href=\"javascript:self.close();\"><img src=\"imgs/chiudi.gif\" alt=\"Indietro\" border=\"0\"></a></td></tr>";
                }
                return $error;
        }
        
        function detail()  {
		  $content = '<table width="500" border="0" cellspacing="0" cellpadding="4" class="plain" align="center">
	<tr>
	 <td colspan="2" class="tit01" align="center" style="line-height:normal"><h1>'.$this->titolo.'</h1></td>
	</tr>
	<tr>
      <td colspan="2" background="../images/bkg_tratt_horiz.gif"><img src="../images/spacer.gif" width="50" height="10"></td>
	</tr>
	<tr>
	 <td colspan="2" align="right">'.$this->data.'</td>
	</tr>
	<tr>
	 <td colspan="2">'.$this->testo.'</td>
	</tr>
	<tr>
      <td colspan="2" background="../images/bkg_tratt_horiz.gif"><img src="../images/spacer.gif" width="50" height="10"></td>
	</tr>
	<tr>
	 <td colspan="2"><input type="button" value="scrivi all\'autore" onclick="location.href=\'mailto:'.$this->mail_autore.'\'"></td>
	</tr>
</table>';
		return $content;
		}
}
?>